package org.example.managementsystem.service;

import org.example.managementsystem.model.DeviceScrap;
import org.example.managementsystem.repository.DeviceScrapDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 设备报废服务层
 */
@Service
public class DeviceScrapService {
    private final DeviceScrapDao deviceScrapDao;

    @Autowired
    public DeviceScrapService(DeviceScrapDao deviceScrapDao) {
        this.deviceScrapDao = deviceScrapDao;
    }

    /**
     * 提交设备报废申请
     */
    public void submitScrap(
            Integer repairId,
            String description) {

        // 创建报废对象,更新报废表
        DeviceScrap scrap = new DeviceScrap();
        scrap.setRepairId(repairId);
        scrap.setDescription(description);
        scrap.setIsApproved(false);
        scrap.setStatus(false);

        deviceScrapDao.insertScrap(scrap);
    }

    public void submitScrap(DeviceScrap scrap){
        deviceScrapDao.insertScrap(scrap);
    }

    /**
     * 更新报废状态
     */
    public void updateScrap(DeviceScrap scrap) {
        deviceScrapDao.updateScrap(scrap);
    }

    /**
     * 获取所有报废申请
     */
    public List<DeviceScrap> getAllScraps() {
        return deviceScrapDao.getAllScraps();
    }

    /**
     * 获取所有未审核的报废申请
     */
    public List<DeviceScrap> getAllUnreviewedScraps() {
        return deviceScrapDao.getAllUnreviewedScraps();
    }

    /**
     * 根据ID获取报废申请
     */
    public DeviceScrap getScrapById(int scrapId) {
        return deviceScrapDao.getScrapById(scrapId);
    }

    /**
     * 根据报修ID获取报废申请
     */
    public List<DeviceScrap> getScrapByRepairId(int repairId) {
        return deviceScrapDao.getScrapByRepairId(repairId);
    }

    /**
     * 根据Id删除报废申请
     */
    public void deleteScrap(int scrapId) {
        deviceScrapDao.deleteScrap(scrapId);
    }
}